package main

import (
	. "nowcoder/common"
)

/**
 *
 * @param root TreeNode类 the root of binary tree
 * @return int整型二维数组
 */
func threeOrders(root *TreeNode) [][]int {
	// write code here
	result := make([][]int, 3)
	for i := range result {
		result[i] = make([]int, 0)
	}

	if root == nil {
		return result
	}

	preOrder(root, &result[0])
	midOrder(root, &result[1])
	postOrder(root, &result[2])

	return result
}

func preOrder(node *TreeNode, result *[]int) {
	if node == nil {
		return
	}
	*result = append(*result, node.Val)
	preOrder(node.Left, result)
	preOrder(node.Right, result)
}

func midOrder(node *TreeNode, result *[]int) {
	if node == nil {
		return
	}
	midOrder(node.Left, result)
	*result = append(*result, node.Val)
	midOrder(node.Right, result)
}

func postOrder(node *TreeNode, result *[]int) {
	if node == nil {
		return
	}
	postOrder(node.Left, result)
	postOrder(node.Right, result)
	*result = append(*result, node.Val)
}

func main() {
	threeOrders(nil)
}
